package cn.yunhe.service;

import cn.yunhe.dao.UserMapper;
import cn.yunhe.entity.User;
import cn.yunhe.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

public class UserService {
    SqlSession session = null;
    UserMapper userMapper = null;

    /*获取session*/
    private void init(){
        session = SqlSessionFactoryUtil.getSqlSession();
        userMapper = session.getMapper(UserMapper.class);
    }
    // 关闭session
    private  void destory(){
        session.commit();
        session.close();
    }

    //登录
    public User login(User user){
        init();
        User u = userMapper.login(user);
        destory();
        return u;
    }
    //注册
    public boolean reg(User user){
        init();
        boolean flag = userMapper.reg(user);
        destory();
        return flag;
    }




}
